var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllers();
//builder.Services.AddCors(option => option.AddPolicy("cors", c => c.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod()));
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}

app.UseHttpsRedirection();

app.UseAuthorization();//身份认证
//app.UseCors("cors");//跨域
app.MapControllers();
app.MapGet("/", () => "index");
app.MapMethods("/Methods", new[] { "GET", "POST", "PUT", "DELETE" }, (HttpRequest req) =>
{
    string json = "";
    json = new RequestHelper().Get_Get_Json(req);
    return json;
});
app.MapPost("/goods", (Goods goods) =>
{
    return $"GName={goods.GName}GId={goods.GId}Price={goods.Price}";
});
app.MapPost("/logon", (userlogon ul) =>
 {
     UserHelper lg = new UserHelper();
     re_base rb = new re_base();
     if (lg.check_user_pwd(ul))
     {
         rb.code = 1;
         rb.info = "登录成功";
         return Results.Ok(rb);
     }
     else
     {
         rb.code = 0;
         rb.info = "账号或密码错误";
         return Results.Ok(rb);
     }
 });
app.MapPost("/user/info", (string uuid) =>
 {
     UserHelper lg = new UserHelper();
     re_user ru = new re_user();
     string user = lg.checke_token(uuid);
     if (!string.IsNullOrEmpty(user))
     {
         ru.code = 1;
         ru.info = "成功";
         ru.user = user;
         ru.uuid = uuid;
     }
     return ru;
 });
app.Run();
